﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace Light.Utility
{
    public class Memory
    {
        
        private long _pageFileSize = -9223372036854775808L;
        private long _pysicalMemorySize = -9223372036854775808L;
        private long _virtualMemorySize = -9223372036854775808L;

        
        private Memory()
        {
        }

        internal static Memory[] Get()
        {
            List<Memory> list = new List<Memory>();
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalMemoryConfiguration");
            foreach (ManagementObject obj2 in searcher.Get())
            {
                Memory item = new Memory();
                if (obj2.Properties["TotalPageFileSpace"].Value != null)
                {
                    item._pageFileSize = long.Parse(obj2.Properties["TotalPageFileSpace"].Value.ToString());
                }
                if (obj2.Properties["TotalVirtualMemory"].Value != null)
                {
                    item._virtualMemorySize = long.Parse(obj2.Properties["TotalVirtualMemory"].Value.ToString());
                }
                if (obj2.Properties["TotalPhysicalMemory"].Value != null)
                {
                    item._pysicalMemorySize = long.Parse(obj2.Properties["TotalPhysicalMemory"].Value.ToString());
                }
                list.Add(item);
            }
            return list.ToArray();
        }

        
        public long TotalPageFileSpace
        {
            get
            {
                return this._pageFileSize;
            }
        }

        public long TotalPhysicalMemory
        {
            get
            {
                return this._pysicalMemorySize;
            }
        }

        public long TotalVirtualMemory
        {
            get
            {
                return this._virtualMemorySize;
            }
        }
    }


}
